//
//  AddCardRetypePasswordController.m
//  HuLaQuan
//
//  Created by hok on 1/21/16.
//  Copyright © 2016 Jianghao. All rights reserved.
//

#import "AddCardRetypePasswordController.h"

#import "FirstSetPayPasswordEngine.h"


//Jumpt Back To
#import "BankCardListViewController.h"
#import "QRCodeViewController.h"
#import "GenericConvenientPayHomeController.h"

@interface AddCardRetypePasswordController ()

@property (nonatomic,strong) FirstSetPayPasswordEngine *setPayPasswordEngine;

@end

@implementation AddCardRetypePasswordController

-(FirstSetPayPasswordEngine *)setPayPasswordEngine
{
    if (!_setPayPasswordEngine) {
        _setPayPasswordEngine = [[FirstSetPayPasswordEngine alloc] init];
    }
    return _setPayPasswordEngine;
}
-(NSString *)finish:(NSString *)pwd{
    NSLog(@"retype %@",self.passwordAndInfos);
    if ([pwd isEqualToString:self.passwordAndInfos[@"password"]]) {
        
        [YuNetworkStatusUtilities showProgressMessage:NETWORK_LOADING];
        [self.setPayPasswordEngine setPayPassword:pwd];
        
        
    }else{
        [self.view makeToast:kPasswordRetypeNotEqual];
    }
    
    //[self performSegueWithIdentifier:@"ShowAddCardInfoFromRetype" sender:self];
    
    return pwd;
}

#pragma mark - Call Back
- (void)setPayPasswordFinish:(NSNotification*) notification
{
    
    [YuNetworkStatusUtilities dismissHUD];
    
    NSDictionary *messageDic = [notification object];//获取到传递的对象
    if ([messageDic[@"isSuccess"] boolValue]) {
        
        UIAlertController *x = [UIAlertController alertWithTitle:@"提示" andMessage:@"设置支付密码成功，请继续输入银行卡信息进行绑定" andBlock:^(UIAlertAction *action ) {
            if ([action.title isEqualToString:@"好的"]) {
                [self performSegueWithIdentifier:@"ShowAddCardInfoFromRetype" sender:self];
            }
            
        }  type:@"confirm"];
        [self presentViewController:x animated:YES completion:nil];
    }else{
        [self showNetWorkError:messageDic[@"message"]];
        
    }
}
#pragma mark - Life Cycle
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    
    // [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setPayPasswordFinish:) name:@"SetPayPasswordFinish" object:nil];
    
}
- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:YES];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"SetPayPasswordFinish" object:nil];
    
}

#pragma mark - Navigation Back
- (void)goBackAction
{
    
    UIAlertController *x = [UIAlertController alertWithTitle:@"提示" andMessage:@"是否放弃绑定银行卡操作" andBlock:^(UIAlertAction *action ) {
        if ([action.title isEqualToString:@"好的"]) {
            if ([self.navigationController.viewControllers[1] isKindOfClass:[BankCardListViewController class]])
            {
                [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
            }
            else if ([self.navigationController.viewControllers[1] isKindOfClass:[QRCodeViewController class]])
            {
                [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
            }else if([self.navigationController.viewControllers[1] isKindOfClass:[GenericConvenientPayHomeController class]])
            {
                [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
            }else{
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
        
    }  type:@"confirmAndCancel"];
    [self presentViewController:x animated:YES completion:nil];
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
